package com.lln.cjcx.style;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.util.StyleUtil;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.AbstractCellStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Workbook;

/**
 * 头与内容是一样的风格，头也使用内容风格，也就不存在头的说法
 *
 * @author LiLinnan
 * @version 1.0
 * @date 2020/1/30 0:54
 */

public final class SimpleStyleStrategy extends AbstractCellStyleStrategy {

	private WriteCellStyle writeCellStyle;

	private CellStyle cellStyle;

	public SimpleStyleStrategy(WriteCellStyle writeCellStyle) {
		this.writeCellStyle = writeCellStyle;
	}

	@Override
	protected void initCellStyle(Workbook workbook) {
		if (writeCellStyle != null) {
			cellStyle = StyleUtil.buildContentCellStyle(workbook, writeCellStyle);
		}
	}

	@Override
	protected void setHeadCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
		if (cellStyle == null) {
			return;
		}
		cell.setCellStyle(cellStyle);
	}

	@Override
	protected void setContentCellStyle(Cell cell, Head head, Integer relativeRowIndex) {
		if (cellStyle == null) {
			return;
		}
		cell.setCellStyle(cellStyle);
	}
}
